<template>
	<view class="content">
		<view class="uni-container statistics_bg">
			<uni-table ref="table" border stripe v-if="type==0">
				<uni-tr>
					<uni-th width="40" align="center">原料名称</uni-th>
					<uni-th width="40" align="center">库存数量kg</uni-th>
					<uni-th width="40" align="center">预计销售数量</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData" :key="index">
					<uni-td align="center">{{ item.wlmc }}</uni-td>
					<uni-td align="center">
						<view class="name">{{ item.qty }}</view>
					</uni-td>
					<uni-td align="center">0</uni-td>
				</uni-tr>
			</uni-table>
			<uni-table ref="table" border stripe v-if="type==1">
				<uni-tr>
					<uni-th width="140" align="center">原料名称</uni-th>
					<uni-th width="30" align="center">库存数量kg</uni-th>
					<uni-th width="20" align="center">总托数</uni-th>
					<uni-th width="40" align="center">安全库存</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData" :key="index">
					<uni-td align="center">{{ item.f_wlmc }}</uni-td>
					<uni-td align="center">
						<view class="name">{{ item.weight }}</view>
					</uni-td>
					<uni-td align="center">{{ item.total_count}}</uni-td>
					<uni-td align="center">{{ item.safetystock}}</uni-td>
				</uni-tr>
			</uni-table>
			<uni-table ref="table" border stripe v-if="type == 2">
				<uni-tr>
					<uni-th width="40" align="center">货架</uni-th>
					<uni-th align="center">物料名称</uni-th>
					<uni-th width="40" align="center">批次</uni-th>
					<uni-th width="40" align="center">数量pcs</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData" :key="index">
					<uni-td align="center">{{ item.pod_code }}</uni-td>
					<uni-td align="center">
						<view class="name">{{ item.f_wlmc_replaced }}</view>
					</uni-td>
					<uni-td align="center">{{ item.barcode }}</uni-td>
					<uni-td align="center">{{ item.f_totalquantity }}</uni-td>
				</uni-tr>
			</uni-table>
			<uni-table ref="table" border stripe v-if="type == 3">
				<uni-tr>
					<uni-th width="40" align="center">货架</uni-th>
					<uni-th width="40" align="center">原料名称</uni-th>
					<uni-th width="40" align="center">批次</uni-th>
					<uni-th width="40" align="center">数量pcs</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData" :key="index">
					<uni-td align="center">{{ item.pod_code }}</uni-td>
					<uni-td align="center">
						<view class="name">{{ item.f_wlmc_replaced }}</view>
					</uni-td>
					<uni-td align="center">{{ item.f_ph_replaced }}</uni-td>
					<uni-td align="center">{{ item.f_realcount }}</uni-td>
				</uni-tr>
			</uni-table>
		</view>
	</view>
</template>

<script>
	
	import {RealTimeInventoryAll,RealTimeInventoryDetaiAll} from '../../common/inventory_api.js'
	
	export default {
		data() {
			return {
				type:0,//0:成品 1：原料
				tableData:[],
			}
		},
		onLoad(option) {
			uni.setNavigationBarTitle({
				title: "库存明细"
			})
			this.type = option.type;
			console.log("onLoad.type:", this.type)
			this.loadData();
		},
		
		methods: {
			loadData(){
				if (this.type == 0 || this.type == 1) {
					RealTimeInventoryAll(this.type).then(res=>{
						if (this.type == 1){
							var array = [];
							for (var i = 0; i < res.length; i++) {
								var item = res[i];
								item.weight = parseFloat(item.weight.toFixed(2));
								item.safetystock = parseInt(item.safetystock);
								array.push(item);
							}	
							this.tableData = array;
						}
						else {
							this.tableData = res;
						}
					});
				} else {
					RealTimeInventoryDetaiAll(this.type).then(res=>{
						var array = [];
						for (var i = 0; i < res.length; i++) {
							var item = res[i];
							if (item["f_wlbm_replaced"] == '') continue;
							array.push(item);
						}
						this.tableData = array; 
					});
				}
				
				
			},

		},
	}
</script>

<style>
	@import url("inventory-detail.css");
</style>
